from sqlalchemy import Column
from sqlalchemy.dialects.mysql import INTEGER, VARCHAR, BOOLEAN

from utils.db import Base, NotNullColumn, model_to_dict, db, models_to_list


class EventEngine(Base):
    __tablename__ = 'tb_event_engine'
    id = Column(INTEGER(11), primary_key=True)
    interview_id = NotNullColumn(VARCHAR(64))              # 面试编号
    interview_evaluation = NotNullColumn(VARCHAR(64))      # 面试评价
    name = NotNullColumn(VARCHAR(64))                      # 姓名
    age = NotNullColumn(VARCHAR(64))                       # 年龄
    native_place = NotNullColumn(VARCHAR(64))              # 籍贯
    education = NotNullColumn(VARCHAR(64))                 # 学历
    time_to_current_city = NotNullColumn(VARCHAR(64))      # 到现有城市时间
    work_status = NotNullColumn(VARCHAR(64))               # 当前工作状态
    habitation = NotNullColumn(VARCHAR(64))                # 居住地点
    social_security = NotNullColumn(VARCHAR(64))           # 社保状况
    intented_schedule_of_week = NotNullColumn(VARCHAR(64))    # 意向天数
    intented_work_time_one_day = NotNullColumn(VARCHAR(64))   # 意向时间
    intended_industry = NotNullColumn(VARCHAR(64))            # 意向行业
    intended_shop = NotNullColumn(VARCHAR(64))                # 意向门店
    intended_brand = NotNullColumn(VARCHAR(64))               # 意向品牌
    intended_position = NotNullColumn(VARCHAR(64))            # 意向岗位
    intended_district = NotNullColumn(VARCHAR(64))            # 意向区域
    intended_region = NotNullColumn(VARCHAR(64))              # POI(商圈)
    transportation = NotNullColumn(VARCHAR(64))               # 交通方式
    commute_time = NotNullColumn(VARCHAR(64))                 # 通勤时间
    work_style = NotNullColumn(VARCHAR(64))                   # 全职/兼职
    food_house_for_free = NotNullColumn(VARCHAR(64))          # 包吃住
    industry_experience = NotNullColumn(VARCHAR(64))          # 行业背景
    shop_experience = NotNullColumn(VARCHAR(64))              # 门店背景
    brand_experience = NotNullColumn(VARCHAR(64))             # 品牌背景
    position_experience = NotNullColumn(VARCHAR(64))          # 岗位背景
    work_experience_time = NotNullColumn(VARCHAR(64))         # 岗位年限
    health_certificate = NotNullColumn(VARCHAR(64))           # 健康证
    qualified_certificate = NotNullColumn(VARCHAR(64))        # 行业资格证
    advantage = NotNullColumn(VARCHAR(64))                    # 优点
    shortcoming = NotNullColumn(VARCHAR(64))                  # 缺点
    apparent_age = NotNullColumn(VARCHAR(64))                 # 外观年龄
    character = NotNullColumn(VARCHAR(64))                    # 内外向性格
    talk = NotNullColumn(VARCHAR(64))                         # 谈吐流利
    polite_language = NotNullColumn(VARCHAR(64))              # 用语礼貌
    smile = NotNullColumn(VARCHAR(64))                        # 面带微笑
    sight = NotNullColumn(VARCHAR(64))                        # 视线飘忽
    is_delete = NotNullColumn(BOOLEAN, default=False)


@model_to_dict
def add(**kw):
    return db.add(EventEngine(**kw))


@model_to_dict
def get(interview_id):
    r = db.master.query(EventEngine).filter_by(interview_id=interview_id).scalar()
    return r


@models_to_list
def get_by_page(page, page_size):
    offset = (page - 1) * page_size
    return db.master.query(EventEngine).filter_by(is_delete=False).order_by(EventEngine.id.desc()).offset(offset).limit(page_size).all()


def update(interview_id, **kwargs):
    db.master.query(EventEngine).filter_by(interview_id=interview_id).update(kwargs)
    db.commit()


def add_or_update(**kwargs):
    data_exists = get(kwargs.get("interview_id"))
    if data_exists:
        update(**kwargs)
    else:
        add(**kwargs)
